
package com.hlkj.pay.app.merchant.ext.impl.baofu;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import com.hlkj.framework.common.pojo.CommonResult;
import com.hlkj.framework.common.util.json.JsonUtils;
import com.hlkj.framework.extension.annotation.Extension;
import com.hlkj.pay.app.merchant.ext.ChannelMerchantAccessExtPt;
import com.hlkj.pay.app.merchant.ext.MerchantExtConstant;
import com.hlkj.pay.app.merchant.ext.dto.access.*;
import com.hlkj.pay.app.merchant.ext.impl.baofu.dto.BaoFuConfig;
import com.hlkj.pay.app.merchant.ext.impl.baofu.handler.BaofuMerchantCommonParamsHandle;
import com.hlkj.pay.app.merchant.ext.impl.fuyou.utils.FuYouCallBackParamsParseUtil;
import com.hlkj.pay.app.merchant.ext.impl.lakala.dto.LakalaAccessExtentDto;
import com.hlkj.pay.app.merchant.ext.impl.lakala.dto.LakalaAppChannelParams;
import com.hlkj.pay.dto.merchant.AccessChannelParamsDto;
import com.hlkj.pay.dto.merchant.MerchantAccessDto;
import com.hlkj.pay.infrastructure.model.pay.ProviderChannelConfigDO;
import com.hlkj.pay.vo.order.resp.MerchantProductQueryResp;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 拉卡拉进件操作
 * 
 * @author HlpayTeam
 * @date 2024/09/26 10:25
 */
@Slf4j
@Repository
@RequiredArgsConstructor
@Extension(bizId = MerchantExtConstant.CHANNEL_BAOFU)
public class BaofuMerchantAccessExtPt implements ChannelMerchantAccessExtPt {

    private final BaofuMerchantCommonParamsHandle baofuMerchantCommonParamsHandle;

    @Override
    public void channelConfigCheck(ChannelMerchantAccessCommonContext channelMerchantAccessCommonContext) {
        CommonResult<BaoFuConfig> configCommonResult = baofuMerchantCommonParamsHandle.baoFuConfig(channelMerchantAccessCommonContext.getProviderChannelConfig(),
                channelMerchantAccessCommonContext.isTest());
        if (!configCommonResult.isSuccess()) {
            channelMerchantAccessCommonContext.setRemark(configCommonResult.getMsg());
            channelMerchantAccessCommonContext.setProcessStatus(false);
        }
    }

    @Override
    public void merchantAccess(ChannelMerchantAccessContext channelMerchantAccessContext) {
        channelMerchantAccessContext.setRemark("宝付当前不支持进件");
        channelMerchantAccessContext.setProcessStatus(false);
    }

    @Override
    public String requestUrl(MerchantAccessDto merchantAccessInfoDO) {

        return null;
    }

    @Override
    public String channelParams(AccessChannelParamsDto accessChannelParamsDto) {
        LakalaAppChannelParams params = new LakalaAppChannelParams();
        params.setCustomerNo(accessChannelParamsDto.getSubMchId());
        LakalaAccessExtentDto lakalaAccessExtentDto = JsonUtils.parseObject(accessChannelParamsDto.getExtendA(), LakalaAccessExtentDto.class);
        params.setMerInnerNo(lakalaAccessExtentDto.getMerInnerNo());
        params.setMerCupNo(lakalaAccessExtentDto.getMerCupNo());
        params.setTermId(lakalaAccessExtentDto.getTermNo());
        return JsonUtils.toJsonStringNotNull(params);
    }

    @Override
    public void merchantAccessQuery(ChannelMerchantAccessQueryContext channelMerchantAccessQueryContext) {
    }

    @Override
    public void merchantSign(ChannelMerchantAccessSignContext channelMerchantAccessSignContext) {
    }

    @Override
    public void merchantSignQuery(ChannelMerchantAccessSignContext channelMerchantAccessSignContext) {

    }

    @Override
    public void merchantBusinessOpen(ChannelMerchantBusinessContext channelMerchantBusinessContext) {
    }

    @Override
    public void wechatConfigInit(ChannelMerchantBusinessContext channelMerchantBusinessContext) {
    }

    @Override
    public void wechatConfigAdd(ChannelMerchantBusinessContext channelMerchantBusinessContext) {
    }

    @Override
    public void wechatConfigQuery(ChannelMerchantAccessAuthQueryContext channelMerchantAccessAuthQueryContext) {

    }

    @Override
    public void wechatAuthConfig(ChannelMerchantBusinessContext channelMerchantBusinessContext) {
    }

    @Override
    public boolean authConfigQueryType() {
        return true;
    }

    @Override
    public void wechatAuthQuery(ChannelMerchantAccessAuthQueryContext channelMerchantAccessAuthQueryContext) {
    }

    @Override
    public void alipayAuthConfig(ChannelMerchantBusinessContext channelMerchantBusinessContext) {
    }

    @Override
    public void alipayAuthQuery(ChannelMerchantAccessAuthQueryContext channelMerchantAccessAuthQueryContext) {
    }

    @Override
    public MerchantAccessCallBackDto accessCallBackParamsParse(HttpServletRequest callBackBody, ProviderChannelConfigDO providerChannelConfigDO) {
        return null;

    }

    @Override
    public CommonResult<String> accessCallbackParse(String callBackBody, List<ProviderChannelConfigDO> channelConfigDOList) {
        return null;
    }

    @Override
    public MerchantBusinessCallBackDto businessCallBackParamsParse(String callBackBody, ProviderChannelConfigDO providerChannelConfigDO) {
        return FuYouCallBackParamsParseUtil.businessCallBackParamsParse(callBackBody);
    }

    @Override
    public boolean verify(String callBackBody, ProviderChannelConfigDO providerChannelConfigDO) {
        return true;
    }

    @Override
    public String callBackResponse(CommonResult commonResult) {
        if (commonResult.isSuccess()) {
            return "{\"code\":\"SUCCESS\",\"message\":\"执行成功\"}";
        }
        else {
            return "{\"code\":\"FAIL\",\"message\":\"+" + commonResult.getMsg() + "\"}";
        }
    }

    @Override
    public void termAdd(ChannelMerchantTermContext channelMerchantTermContext) {

    }

    @Override
    public void reloadMerchantAuth(ChannelMerchantBusinessContext channelMerchantBusinessContext) {
    }

    @Override
    public void channelSplit(ChannelMerchantBusinessContext channelMerchantBusinessContext) {

    }

    @Override
    public void productUpdate(ChannelMerchantBusinessContext channelMerchantBusinessContext) {

    }

    @Override
    public Integer queryMerAuthStatus(ChannelMerchantAccessAuthQueryContext channelMerchantAccessAuthQueryContext) {
        return null;
    }

    @Override
    public MerchantProductQueryResp productQuery(ChannelMerchantBusinessContext channelMerchantBusinessContext) {
        return null;
    }

    @Override
    public MerchantChannelSplitCallBackDto easySplitCallBackParamsParse(HttpServletRequest request, ProviderChannelConfigDO providerChannelConfigDO) {
        return null;
    }

}
